package com.dian.modules.inv.poi.verify;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.dian.modules.base.entity.GoodsEntity;
import com.dian.modules.base.entity.WarehouseEntity;
import com.dian.modules.base.service.GoodsService;
import com.dian.modules.base.service.WarehouseService;
import com.dian.modules.inv.poi.vo.GoodsStockInitExportVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 库存初始导入校验类
 *
 * @author xiaolai
 * @email xiaolai@9dyun.cn
 * @date 2019-06-29 15:53:12
 */
@Component
public class GoodsStockInitExcelVerifyHandler implements IExcelVerifyHandler<GoodsStockInitExportVO> {
    protected Logger logger = LoggerFactory.getLogger(GoodsStockInitExcelVerifyHandler.class);
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private WarehouseService warehouseService;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(GoodsStockInitExportVO employee) {
        //验证数据是否完整
        GoodsEntity goodsEntity = goodsService.queryByCode(employee.getGoodsCode());
        if(goodsEntity==null){ //true代表可以用
            return new ExcelVerifyHandlerResult(false,"无效的商品信息");
        }
        WarehouseEntity warehouseEntity = warehouseService.queryByCode(employee.getWarehouseCode());
        if(warehouseEntity==null){ //true代表可以用
            return new ExcelVerifyHandlerResult(false,"无效的仓库信息");
        }

        return new  ExcelVerifyHandlerResult(true);
    }
}
